#! /bin/sh

source /etc/rc.d/common

/bin/echo "Bringing up loopback interface..."
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo

# Set a temporary host name
/bin/hostname localhost

# Start the EARLY user settable services
for i in ${EARLY_SERVICES}; do
    if check_enabled "${i}"; then
        ${RC_D_PREFIX}/${i} start
    fi
done

if [ -f "/etc/crypttab" ]; then
    /bin/echo "Starting disk encryption (early)..."
    init_crypto 1
fi

/bin/echo "Loading the Brocade 10G Ethernet driver..."
/sbin/modprobe bna

/bin/echo "Loading the Mellanox ConnectX-4 and Connect-IB core driver..."
/sbin/modprobe mlx5_core

/bin/echo "Loading the QLogic FastLinQ 4xxxx Ethernet driver..."
/sbin/modprobe qede

#/bin/echo "Loading the Microsemi Switchtec NTB driver..."
#/sbin/modprobe ntb_hw_switchtec
/sbin/modprobe cls_switchtec

#/bin/echo "Loading the Virtual Ethernet over NTB Transport driver..."
#/sbin/modprobe -s ntb_netdev

/bin/echo "Loading the Linux Ethernet Bonding driver..."
/sbin/modprobe bonding

if [ -x /etc/rc.d/rc.network ]; then
    /etc/rc.d/rc.network start
fi

if [ -x /etc/rc.d/rc.syslogd ]; then
    /etc/rc.d/rc.syslogd start
fi

/bin/echo "Starting vixie-cron..."
/usr/sbin/cron

if [ -s /etc/ntp_server ]; then
    /bin/echo "Setting system date/time via NTP..."
    /usr/sbin/ntpd -n -q -N -p `/bin/cat /etc/ntp_server`
fi

if ! /bin/grep esos_iso /proc/cmdline > /dev/null 2>&1; then
    if [ -x /etc/rc.d/rc.kdump ]; then
        /bin/echo "Loading crash dump kernel (kexec)..."
        /etc/rc.d/rc.kdump
    fi
fi

/bin/echo "Loading the QLogic Fibre Channel HBA module..."
if [ -f "/lib/modules/$(/bin/uname -r)/extra/qla2xxx_scst.ko" ]; then
    /sbin/modprobe qla2xxx_scst
else
    /sbin/modprobe qla2xxx
fi
/bin/sleep 5

if [ -f "/lib/modules/$(/bin/uname -r)/extra/celerity16fc.ko" ]; then
    /bin/echo "Loading the ATTO Celerity 16Gb/32Gb FC HBA module..."
    /sbin/modprobe -s celerity16fc
fi

/bin/echo "Starting irqbalance..."
/usr/sbin/irqbalance

/bin/echo "Fixing /opt/sbin permissions..."
for i in $(/bin/ls /opt/sbin); do
    if [ ! -x "/opt/sbin/${i}" ]; then
        /bin/chmod +x /opt/sbin/${i}
    fi
done

/bin/echo "Loading the bcache module..."
/sbin/modprobe bcache

if [ -f "/lib/modules/$(/bin/uname -r)/extra/zfs/zfs.ko" ]; then
    /bin/echo "Loading the ZFS module..."
    /sbin/modprobe zfs
    /bin/echo "Starting the ZFS Event Daemon..."
    /usr/sbin/zed -p /var/run/zed.pid
fi

/bin/echo "Loading the NVMeoF target modules..."
/sbin/modprobe nvmet-rdma
/sbin/modprobe nvmet-fc

# Start the LATE user settable services
for i in ${LATE_SERVICES}; do
    if check_enabled "${i}"; then
        ${RC_D_PREFIX}/${i} start
    fi
done

if [ -f "/etc/crypttab" ]; then
    /bin/echo "Starting disk encryption (late)..."
    init_crypto 1
fi

/bin/echo "Executing /etc/rc.local..."
if [ -f /etc/rc.local ]; then
    /bin/sh /etc/rc.local
fi

# For a nice pretty login screen
/usr/bin/clear
